package cn.xiaomubiao.oschine.widget;

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.xiaomubiao.oschine.R;

/**
 * Created by hasee on 2017/4/2.
 */

public class TweetsPagerView extends LinearLayout {
    @BindView(R.id.recyler_pager)
    XRecyclerView mXRecyler;
    @BindView(R.id.refresh_pager)
    SwipeRefreshLayout mRefresh;

    private OnRefreshListener mRefreshListener;
    private List mListData;
    private int mLayoutResId;
    private View mItemView;


    public TweetsPagerView( Context context ) {
        this(context, null);
    }

    public TweetsPagerView( Context context, AttributeSet attrs ) {
        this(context, attrs, 0);
    }

    public TweetsPagerView( Context context, AttributeSet attrs, int defStyleAttr ) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    private void initView() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.view_tweets_pager_layout, this, false);
        addView(view);
        ButterKnife.bind(this);

        mRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                if(mRefreshListener != null) {
                    mRefreshListener.onRefresh();
                }
            }
        });

//        mXRecyler.setAdapter();

    }

    //为XRecylerView设置数据的方法
    public void setListData(ArrayList data) {
        mListData = data;
    }

    public void setItemView(View itemView) {
        mItemView = itemView;
    }



    public void setOnRefreshListener(OnRefreshListener listener) {
        mRefreshListener = listener;
    }

    interface OnRefreshListener{
        void onRefresh();
    }


    class TweetsXRecylerAadapter extends RecyclerView.Adapter{

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder( ViewGroup parent, int viewType ) {

            return null;
        }

        @Override
        public void onBindViewHolder( RecyclerView.ViewHolder holder, int position ) {

        }

        @Override
        public int getItemCount() {
            return mListData != null ? mListData.size():0;
        }
    }


}
